package com.fengwan.wastesort.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.fengwan.wastesort.ui.fragment.*

/**
 * @author : Silence丶J
 * @time : 2019/7/18
 * @description :
 */
class WastePageAdapter(fm: FragmentManager?) : FragmentStatePagerAdapter(fm) {

//    val wasteDryFragment = WasteDryFragment.newInstance()
//    val wasteWetFragment = WasteWetFragment.newInstance()
//    val wasteHarmfulFragment = WasteHarmfulFragment.newInstance()
//    val wasteCycleFragment = WasteCycleFragment.newInstance()

    val wasteDryFragment = WasteSortFragment.newInstance(0)
    val wasteWetFragment = WasteSortFragment.newInstance(1)
    val wasteHarmfulFragment = WasteSortFragment.newInstance(2)
    val wasteCycleFragment = WasteSortFragment.newInstance(3)

    private val titles = arrayListOf("干垃圾", "湿垃圾", "有害垃圾", "可回收垃圾")

    override fun getItem(position: Int): Fragment {
        return when (position) {
            0 -> wasteDryFragment
            1 -> wasteWetFragment
            2 -> wasteHarmfulFragment
            3 -> wasteCycleFragment
            else -> wasteDryFragment
        }
    }

    override fun getCount() = titles.size

    override fun getPageTitle(position: Int): CharSequence? {
        return titles[position]
    }
}